<?php
//延迟开奖
namespace App\Jobs\QiPao;

use App\Jobs\Job;
use App\Services\Tools\RedisService;
use Illuminate\Support\Facades\Log;

class ScreenEndJob extends Job
{
    protected $data;
    const jobName = 'ScreenEndJob';

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($data)
    {
        $this->data = $data;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $activityInfo = $this->data;
        try{
            app('repo_screen')->screenActivityEndPush($activityInfo);
        }catch (\Exception $e){
            //最大重试5次
            $activityInfo['error_num'] = empty($activityInfo['error_num'])?1:$activityInfo['error_num']+1;
            if($activityInfo['error_num'] <5){
                $screenJob = (new ScreenEndJob($activityInfo))->delay($activityInfo['error_num']);
                dispatch($screenJob);
            }
        }
    }

}
